#ifndef __MACHINE_H
#define __MACHINE_H

#include "Common.h"

namespace TimingDiagram
{

    class Machine{
        private:
        int  _numDUnits;
        int  _numRegisters;
        DUnit* _dUnits; //A 'map' of D-Units; a value of -1 indicates free, a value >= 0 is the number of cycles the unit will take
        Register* _registers; //A 'map' of registers; 0 indicates free, 1 indicates in use

        int  _addTime;
        int  _mulTime;
        int  _iuTime;

        std::vector<Instruction> _instructions;

        std::string _fileName;
        std::stringstream _program;
        int _lastLineLength;

        bool _loaded;

        public:
        Machine(int numDUnits, int numRegisters, int addTime, int mulTime, int iuTime);
        ~Machine();

        void loadProgram(std::string fileName);
        void outputDiagram();

        private:
        int getNextFreeDUnit();
        int getDUnitAvailableNext();
        int getNextAvailableRegister();

        void computeInstructionDependencies();
        int getNumberOfRegistersUsed();
    };

}

#endif
